<template> 
	<view class="content" :class="isProp?'isMove':''">
		<view class="top">
			<view class="typeContent">
				<view class="change">选择转账类型</view>
				<view class="cords" @tap="checkRecord">互转明细</view>
			</view>
			<view class="currency">
				<picker @change="bindPickerChange" :value="index" :range="navList">
					<view class="uni-input">{{navList[index]}}</view>
				</picker>
			</view>
		</view>
		<view class="text">账号</view>
		<view class="inputContent">
			<input placeholder="请输入转账账号" placeholder-class="placeholder" v-model="toUserPhone" class="input" type="number" maxlength="11" />
			<image src="../../static/recharge/close.png" class="closeImg" @tap="close"></image>
		</view>
		
		<view class="text">{{index == 0?'多多券':index == 1?'权益积分':'快乐豆'}}</view>
		<view class="inputContent">
			<input :placeholder="index == 0?'请输入多多券':index == 1?'请输入权益积分':'请输入快乐豆'"  placeholder-class="placeholder" v-model="amount" class="input" type="number" maxlength="8" />
		</view>
		<view class="tip-content">
			<view>可用{{index == 0?walletInfo.balance:index == 1?walletInfo.greenIntegral:walletInfo.happyBean}}</view>
			<!-- <view>手续费{{walletInfo.withdrawFee}}%</view> -->
		</view>
		<view class="tips-content">转账前请确认好互转账户，一旦转错，积分将无法找回。</view>
		<view class="submit" @tap="submit">确认转账</view>
		<!-- 购买弹窗 -->
		<view class="prop" v-if="isProp">
			<view class="buyProp">
				<image src="../../static/recharge/close.png" class="closeImg" @tap="closeProp"></image>
				<view class="title">转账</view>
				<view class="numTitle">转账金额</view>
				<input placeholder="请输入转账金额" class="input" placeholder-class="placeholder" maxlength="11" type="number" v-model="amount" />
				<view class="numTitle">交易密码</view>
				<input placeholder="请输入交易密码" class="input" placeholder-class="placeholder" password maxlength="11" type="number" v-model="payPassword" />
			  <view class="numTitle">手机号验证码</view>
			  <input placeholder="请输入您的手机号验证码" class="input" placeholder-class="placeholder" password maxlength="8" type="number" v-model="verifyCode"/>
			  <view class="codes" @tap="getCodes">{{text}}</view>
				<view class="sures" @tap="sure">确定</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { sendMsg,userBalance,transfer } from '../../api/api.js'
	export default {
		data() {
			return {
				index:0,
				navList:['多多券','权益积分'],
				// 手机号
				phone:'',
				// 是否展示购买弹窗
				isProp:false,
				text:'获取验证码',
				// 收款用户手机号
				toUserPhone:'',
				// 转账金额
				amount:'',
				// 支付密码
				payPassword:'',
				// 验证码
				verifyCode:'',
				walletInfo:'',  // 钱包信息
			}
		},
		onShow() {
			this.phone = uni.getStorageSync('phone')
			// 获取钱包信息
			this.getuserWalletInfo()
			
		},
		methods: {
			bindPickerChange: function(e) {
			    this.index = e.detail.value
			},
			// 获取钱包信息
			getuserWalletInfo() {
				let data = {}
				userBalance(data).then( res=> {
					this.walletInfo = res.data
					if( this.walletInfo.transferState == 1 ) {
						this.navList = ['多多券','权益积分','快乐豆']
					}else {
						this.navList = ['多多券','权益积分']
					}
				})
			},
			// 查看兑换记录
			checkRecord() {
				uni.navigateTo({
					url:'./exchangeRecord'
				})
			},
			// 清除兑换金额
			close() {
				this.toUserPhone = ''
			},
			// 选择收款方式
			chooseType(item) {
				this.paymentId = item.id
				this.list.forEach( gitem => {
					gitem.isSelect = false
					if( item.id == gitem.id ) {
						gitem.isSelect = true
					}
				})
				this.$forceUpdate()
			},
			//获取验证码
			getCodes(){
				if( this.text != '获取验证码' ) {
					return false
				}
				//判断手机号是否正确
				if((/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.phone))){ 
					let data = {
						phone:this.phone,
						type:7
					}
					sendMsg(data).then(res=> {
						if ( res.code == 200 ) {
							uni.showToast({
								icon:'none',
								title:'验证码已发送，请注意查收~'
							})
							//正确-发送验证码，变化 text 文字
							var seconds = 60;
							this.text = seconds + 's后重新获取';
							let interval = setInterval(()=>{
							  if(seconds > 0){
								  seconds -- ;
								  this.text = seconds + 's后重新获取'
							  }else{
								  this.text = '获取验证码';
								  clearInterval(interval)
							  }
							},1000)
						}
					})
			  }else{
				  uni.showToast({
					  icon:'none',
					  title:'请输入正确的手机号~'
				  })
			  }
			},
			// 打开弹窗
			submit() {
				if( !this.toUserPhone ) {
					uni.showToast({
						icon:'none',
						title:'请输入转账账号'
					})
					return false
				}
				if( !this.amount ) {
					uni.showToast({
						icon:'none',
						title:'请输入金额'
					})
					return false
				}
				this.isProp = true
				this.payPassword = ''
				this.verifyCode = ''
			},
			// 关闭弹窗
			closeProp() {
				this.isProp = false
			},
			// 提交
			sure() {
				if( !this.payPassword ){
					uni.showToast({
						icon:'none',
						title:'请输入支付密码'
					})
					return false
				}
				if( !this.verifyCode ){
					uni.showToast({
						icon:'none',
						title:'请输入验证码'
					})
					return false
				}
				let data = {
					payPassword:this.payPassword,
					verifyCode:this.verifyCode,
					amount:this.amount,
					toUserPhone:this.toUserPhone,
					type:this.index + 1,
				}
				transfer(data).then( res=> {
					uni.showToast({
						icon:'none',
						title:'转账成功，请等待审核~'
					})
					// 获取钱包信息
					this.getuserWalletInfo()
					this.amount = ''
					this.toUserPhone = ''
					this.isProp = false
				})
			}
		}
	}
</script>

<style lang="less">
	.isMove {
		width: 100vw;
		height: 100vh;
		position: fixed;
		top: 0;
	}
	.content {
		.top {
			padding: 30rpx 30rpx 0 30rpx;
			width: 690rpx;
			height: 160rpx;
			background-color: #FE3B33;
			.typeContent {
				display: flex;
				align-items: center;
				justify-content: space-between;
				.change {
					font-size: 30rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #A7CBFF;
					line-height: 42rpx;
				}
				.cords {
					text-align: center;
					width: 140rpx;
					height: 56rpx;
					border-radius: 8rpx;
					border: 1rpx solid #FFFFFF;
					font-size: 26rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
					line-height: 56rpx;
				}
			}
			.currency {
				margin-top: 20rpx;
				font-size: 32rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				line-height: 45rpx;
			}
		}
		.text {
			margin: 36rpx 0 0 34rpx;
			font-size: 30rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #000000;
			line-height: 42rpx;
		}
		.inputContent {
			position: relative;
			.icon {
				left: 30rpx;
				top: 15rpx;
				position: absolute;
				font-size: 32rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #000000;
			}
			.input {
				margin: 30rpx 0 0 30rpx;
				width: 690rpx;
				height: 70rpx;
				border-bottom: 1px solid #F2F2F2;
			}
			.closeImg {
				width: 34rpx;
				height: 34rpx;
				position: absolute;
				right: 30rpx;
				bottom: 23rpx;
			}
			.placeholder {
				font-size: 30rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #CCCCCC;
				line-height: 40rpx;
			}
		}
		.tip-content {
			margin-top: 15rpx;
			margin-left: 30rpx;
			width: 690rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
		    font-size: 24rpx;
		    font-family: PingFangSC-Regular, PingFang SC;
		    font-weight: 400;
		    color: #000000;
		}
	    .tips-content {
			padding-left: 40rpx;
			margin: 100rpx 0 0 30rpx;
			font-size: 24rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #808080;
			width: 650rpx;
			height: 90rpx;
			background: #F2F2F2;
			border-radius: 10rpx;
			line-height: 90rpx;
		}
		.submit {
			margin: 200rpx 0 0 30rpx;
			text-align: center;
			line-height:90rpx ;
			width: 690rpx;
			height: 90rpx;
			background: #FE3B33;
			border-radius: 4rpx;
			font-size: 28rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
		}
		.prop {
			display: flex;
			align-items: center;
			justify-content: center;
			position: absolute;
			top: 0;
			left: 0;
			width: 100vw;
			height: 100vh;
			background: rgba(26, 26, 26, 0.45);
			.buyProp {
				padding-bottom: 40rpx;
				position: relative;
				display: flex;
				align-items: center;
				flex-direction: column;
				width: 560rpx;
				background: #FFFFFF;
				border-radius: 20rpx;
				.closeImg {
					width: 24rpx;
					height: 24rpx;
					position: absolute;
					top: 37rpx;
					right: 25rpx;
				}
				
				.title {
					margin-top: 38rpx;
					font-size: 30rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #1A1A1A;
					line-height: 42rpx;
				}
				.numTitle {
					margin-top: 46rpx;
					width: 470rpx;
					font-size: 26rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #000000;
					line-height: 37rpx;
				}
				.input {
					margin-top: 12rpx;
					height: 88rpx;
					width: 470rpx;
					border-bottom:1rpx solid #F2F2F2 ;
				}
				.placeholder {
					font-size: 24rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #808080;
					line-height: 33rpx;
				}
				.sures {
					margin-top: 60rpx;
					text-align: center;
					line-height: 86rpx;
					width: 470rpx;
					height: 86rpx;
					background: #FE3B33;
					border-radius: 4rpx;
					font-size: 28rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
				}
				.codes {
					position: absolute;
					right: 43rpx;
					bottom: 210rpx;
					font-size: 24rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #FE3B33;
					line-height: 33rpx;
				}
			}
		}
	}
</style>
